package com.yuchen.ishop.seller;

import com.alibaba.dubbo.rpc.protocol.rest.support.ContentType;
import com.yuchen.core.jdbc.BaseDao;
import com.yuchen.ishop.entity.Shop;
import com.yuchen.jaxrs.ResponseUtils;
import com.yuchen.jaxrs.Responses;
import org.nutz.dao.Cnd;
import org.nutz.dao.Condition;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;

/**
 *
 */
@Transactional
@Path("shopService")
@Consumes({MediaType.APPLICATION_JSON, MediaType.TEXT_XML})
@Produces({ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
public class ShopServiceImpl implements ShopService{

    @Autowired
    private BaseDao dao;

    @GET
    @Path("get/{id}")
    @Transactional(readOnly = true)
    public Shop get(@PathParam("id") Long id) {
        return dao.fetch(Shop.class,id);
    }

    @GET
    @Path("findShopBySellerId/{sellerId}")
    @Transactional(readOnly = true)
    public Shop findShopBySellerId(@PathParam("sellerId") Long sellerId) {
        Condition cnd = Cnd.where("sellerId", "=", sellerId);
        return dao.fetch(Shop.class, cnd);
    }

    @POST
    @Path("insertShop")
    public Shop insertShop(Shop shop) {
        return dao.insert(shop);
    }

    @POST
    @Path("updateShop")
    public Responses updateShop(Shop shop) {
        dao.updateIgnoreNull(shop);
        return ResponseUtils.success();
    }
}
